#!/usr/bin/perl 
use DBI;
use CGI;
use TTraker;

& print_header;
& initialize_dbi;
my $form_ref = &parse_input;
my %FORM_DATA = %$form_ref; 
my $num = $FORM_DATA{'empNum'};
my $name = $FORM_DATA{'empName'};
my $job = $FORM_DATA{'empJob'};
my $loc = $FORM_DATA{'empLoc'};
my $cli = $FORM_DATA{'cliID'};
my $task = $FORM_DATA{'taskID'};
# convert task id to UC without spaces
$task =~ tr/a-z/A-Z/;
$task =~ s/^\s*//;
$task =~ s/$\s*//;
$task =~ s/\s+//g;

if ($task eq "") {
	$msg = "NO TASK ID ENTERED";
    select_client_add_task_msg( $num, $name, $job, $loc, $msg);
} else {
    $verify = adm_new_cli_task_verify ($cli, $task);
	if ($verify == 0 ) {		
		& adm_client_task_detail_screen($num, $name, $job, $loc, $cli, $task);
	} else {
		$msg = "$task already exists for $cli!";
    	select_client_add_task_msg ($num, $name, $job, $loc, $msg);
	}
}

db_disconnect();

##################### SUBROUTINES FOLLOW  #####################

sub select_client_add_task_msg
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $empLoc = $_[3];
my $msg = $_[4];
$client_ref = get_clients;
@clients = @$client_ref;

print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_02_adm_activity.html</title>
</head>

<body onload='startUp1()'>

<h2><center>${banner}</center></h2>
<hr/>

<div id='clock'></div>
<div id='box1'>
Employee Number:<br/><br/>
Employee Name:<br/><br/>
Select Client:<br/><br/>
New Task ID:<br/><br/>
</div>
<form id='box2' autocomplete='off' name='startJob' action='${cgi_ref}trak_03_adm_add_client_task.pl' method='post'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<span>$num</span><br/><br/>
<span>$name</span></b><br/><br/>
<select id=cliID name="cliID" tabindex=1 >
ENDHEADER
# add a MASTER element at the start of the list
# print "<option value='NUL'></option>";
# add all clients on the list to the drop down
foreach $cli (@clients) {
   print "<option value=$cli >$cli</option>";
}
print <<ENDHEADER;
</select>
<br/><br/>
<input type="text" size=10 name=taskID />&nbsp&nbsp
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
</form>
</body>
</html>

ENDHEADER

}

sub adm_client_task_detail_screen
{
my $num = $_[0];
my $name = $_[1];
my $job = $_[2];
my $empLoc = $_[3];
my $cli = $_[4];
my $task = $_[5]; 
print <<ENDHEADER;
<html>
<head>
<link rel='stylesheet' type='text/css' href='${css_ref}trak.css' />
<script type='text/javascript' src='${js_ref}trak.js'></script>
<title>trak_03 adm_client_task_detail_screen</title>
</head>
<body>
<h2><center>${banner}</center></h2>
<hr/>
<div id='box5_1'>
<h3>New Task: $task &nbsp&nbsp&nbsp&nbsp Client: $cli</h3>
<form autocomplete='off' name='startJob' action='${cgi_ref}trak_04_adm_add_client_task.pl' method='post'>
<div id='box5_2'>
<input type="hidden" name=empNum value='$num'/>
<input type="hidden" name=empName value='$name'/>
<input type="hidden" name=empJob value='$job'/>
<input type="hidden" name=empLoc value='$loc'/>
<input type="hidden" name=cliID value='$cli'/>
<input type="hidden" name=taskID value='$task'/>
<table>
	<tr>
		<td>Description:</td>
		<td><input type="text" name=description size="48"></td>
	</tr>
	<tr>
		<td>Units:</td>
		<td><input type="text" name=units size="8"></td>
	</tr>
	<tr>
		<td>Standard Min:</td>
		<td><input type="text" name=stdMin size="8"></td>
	</tr>
	<tr>
		<td>Contract Rate:&nbsp&nbsp</td>
		<td><input type="text" name=stdRate size="8"></td>
	</tr>
</table>
<br/><br/>Show on the following lists:
<br/><br/>
<label><input type=checkbox name=show_whs>&nbsp&nbsp&nbsp WHS</label>
<label><input type=checkbox name=show_csr>&nbsp&nbsp&nbsp CSR</label>
<label><input type=checkbox name=show_adm>&nbsp&nbsp&nbsp ADMIN</label>
<br/><br/>
<label><input type=checkbox name=inbound>&nbsp&nbsp&nbsp Inbound</label>
<label><input type=checkbox name=outbound>&nbsp&nbsp&nbsp Outbound</label>
<br/><br/>
<input type='submit' name='submit' value='Proceed'>
<br/><br/>
<a href="${cgi_ref}trak_00_adm_activity.pl?num=$num&name=$name&job=$job&loc=$loc">Return to Activities</a>
<br/><br/>
<b id="warn">$msg</b>
</div>
</form>
</body>
</html>

ENDHEADER
}

